package org.wutopia.examples.sentinel;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/hello")
//    @SentinelResource(value = "hello", blockHandler = "blockHandlerForDeduct", fallback = "fallbackForDeduct")
    public String hello() {
        return "hello";
    }

    @GetMapping("/jb")
//    @SentinelResource(value = "hello", blockHandler = "blockHandlerForDeduct", fallback = "fallbackForDeduct")
    public String jb() {
        return "jb";
    }


    // 熔断降级方法（参数需加Throwable）
    public String fallbackForDeduct(Long userId, Throwable ex) {
        return "服务暂时不可用：" + ex.getMessage();
    }

    // 限流降级方法（参数需加BlockException）
    public String blockHandlerForDeduct(Long userId, BlockException ex) {
        return "系统繁忙，请重试";
    }
}
